package cn.jsj.cxsys.dao;

import java.util.*;
import org.apache.ibatis.annotations.*;
import cn.jsj.cxsys.pojo.*;

public interface ComputerFunction
{
    @Insert({ "insert into tb_pc (pc_num,lab_id) values (#{pcNum},#{labID})" })
    int insertOneComputer(@Param("pcNum") final int pcNum, @Param("labID") final int labID);

    @Select({ "select count(*) from tb_pc where lab_id=#{labID}" })
    int getMaxComputerNumOfLab(final int labID);

    @Results(id = "toComputer", value = { @Result(id = true, property = "pcID", column = "pc_id"), @Result(property = "pcNum", column = "pc_num"), @Result(property = "labID", column = "lab_id"), @Result(property = "state", column = "pc_state"), @Result(property = "description", column = "state"), @Result(property = "labNum", column = "lab_num") })
    @Select({ "select * from vi_computer where lab_id=#{labID} and pc_num=#{pcNum} limit 1" })
    Computer getOneComputer(@Param("labID") final int labID, @Param("pcNum") final int pcNum);

    @ResultMap({ "toComputer" })
    @Select({ "select * from vi_computer where pc_id=#{pcID} limit 1" })
    Computer getOneComputerByID(@Param("pcID") final int pcID);

    @ResultMap({ "toComputer" })
    @Select({ "select * from vi_computer where lab_id=#{labID}" })
    List<Computer> getComputersOfOneLab(@Param("labID") final int labID);

    @ResultMap({ "toComputer" })
    @Select({ "select * from vi_computer" })
    List<Computer> getAllComputers();

    @Select({ "select count(*) from tb_pc" })
    int countNumberOfComputers();

    @ResultMap({ "toComputer" })
    @Select({ "select * from vi_computer where pc_state=-1" })
    List<Computer> getBreakComputers();

    @ResultMap({ "toComputer" })
    @Select({ "select * from vi_computer where pc_state=-1 and lab_id in (select lab_id from tb_lab where lader_id=#{teacherID})" })
    List<Computer> getBreakComputersOfTeacher(final int teacherID);

    @Update({ "update tb_pc set pc_state=-1 , state=#{breakinf} where pc_id=#{pcID} and pc_state<>-1 and pc_state<>0 limit 1" })
    int setBreak(final int pcID, final String breakinf);

    @Delete({ "delete from tb_lab where lab_id=#{labID} and pc_num=#{pcNum} limit 1" })
    int deleteOneLab(final int labID, final int pcNum);

    @Results(id = "toLab", value = { @Result(id = true, property = "labID", column = "lab_id"), @Result(property = "labName", column = "lab_name"), @Result(property = "labNum", column = "lab_num"), @Result(property = "description", column = "description"), @Result(property = "laderName", column = "name"), @Result(property = "laderTeleNumber", column = "tele_number"), @Result(property = "StudentNumber", column = "stu_count") })
    @Select({ "select * from vi_lab where lab_id=(select lab_id from tb_pc where pc_id=#{pcID}) limit 1" })
    Lab getFatherLab(final int pcID);

    @Update({ "update tb_pc set pc_state=0 , state='正常使用' where pc_id=#{pcID} and pc_state=-1 limit 1" })
    int repareComputer(final int pcID);

    @Update({ "update tb_pc set pc_state=#{userID} where pc_id=#{pcID} and pc_state=0" })
    int signInComputer(final int userID, final int pcID);

    @Update({ "update tb_pc set pc_state=0 where pc_id=#{pcID} and pc_state=#{userID}" })
    int signOutComputer(final int userID, final int pcID);
}